{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}	
	<div class="layui-body"> 
{include file='Public/crumbs' /}
		<!-- 内容主体区域 -->
		<div class="shu-body">
			<div class="layui-fluid">
				<form class="layui-form layui-form-pane" action="{:url('update')}" method="post">
				<div class="layui-form-item">
					<label class="layui-form-label">用户组名</label>
				  	<div class="layui-input-inline">
					<input type="text" name="title" id="title" placeholder="用户组名" class="layui-input" value="{notempty name='group'}{$group.title}{/notempty}" required lay-verify="required" autocomplete="off">
                    <input type="hidden" name="id" id="id" value="{notempty name='group' }{$group.id} {/notempty}">
				  	</div>
					<div class="layui-form-mid layui-word-aux">用户组名不能为空</div>
				</div>
				{notempty name='group' }
				{if condition="$group.id neq 1"}
				<div class="layui-form-item">
				  	<label class="layui-form-label">是否启用</label>
				  	<div class="layui-input-inline">
					{notempty name='group' }
					{if condition="$group['status'] eq 1"}
					<input type="checkbox" checked name="status" lay-skin="switch" lay-text="启用|隐藏" lay-filter="switchTest" value="1">
					{else /}
					<input type="checkbox" name="status" lay-skin="switch" lay-text="启用|隐藏" lay-filter="switchTest" value="1">
					{/if}
					{/notempty}
				  	</div>
					<div class="layui-form-mid layui-word-aux"></div>
				</div>
				<div class="layui-form-item layui-form-text">
				  	<label class="layui-form-label">权限选择</label>
				  	<div class="layui-input-block">
						{volist name="rule" id="v"}
						<blockquote class="layui-elem-quote">
							<div>
								<div>
									<div class="shu-qx-title">
										<input lay-ignore name="rules[{$v['id']}]" class="ace ace-checkbox-2 father" type="checkbox" value="{$v['id']}" <?php if(in_array($v['id'],$group['rules'])){echo 'checked="checked"';};?>/>
										<span> {$v['title']}</span>
									</div>
									{notempty name="v.children"}
										<div>
											<div class="layui-row shu-qx-zhi">
												{volist name="v.children" id="vv"}
												<label class="layui-col-md2">
													<input lay-ignore name="rules[{$vv['id']}]" class="ace ace-checkbox-2 children" type="checkbox" value="{$vv['id']}" <?php if(in_array($vv['id'],$group['rules'])){echo 'checked="checked"';};?>/><span> {$vv['title']}</span>
												</label>
													{notempty name='vv.children'}
													{volist name="vv.children" id="vvv"}
													<label class="layui-col-md2">
														<input lay-ignore name="rules[{$vvv['id']}]" class="ace ace-checkbox-2 children" type="checkbox" value="{$vvv['id']}" <?php if(in_array($vvv['id'],$group['rules'])){echo 'checked="checked"';};?>/><span> {$vvv['title']}</span>
													</label>
													{/volist}
												   	{/notempty}
												{/volist}
											</div>
										</div>
									{/notempty}
								</div>
							</div>
						</blockquote>
						{/volist}
				 	</div>
				</div>
				{/if}
				{/notempty}
				{empty name='group'}
				<div class="layui-form-item">
				  	<label class="layui-form-label">是否启用</label>
				  	<div class="layui-input-inline">
					<input type="checkbox" name="status" lay-skin="switch" lay-text="启用|隐藏" lay-filter="switchTest" value="1">
				  	</div>
				</div>
				 <div class="layui-form-item layui-form-text">
					<label class="layui-form-label">权限选择</label>
						 
					{volist name="rule" id="v"}
					<blockquote class="layui-elem-quote">
						<div>
							<div>
								<div class="shu-qx-title">
									 
										<label>
											<input lay-ignore name="rules[{$v['id']}]"
												   class="ace ace-checkbox-2 father" 
											type="checkbox" value="{$v['id']}"/>
											<span class="lbl"> {$v['title']}</span>
										</label>
									 
								</div>
								{notempty name="v.children"}
									<div>
										<div class="layui-row shu-qx-zhi">
											{volist name="v.children" id="vv"}
												<label class="layui-col-md2">
													<input lay-ignore name="rules[{$vv['id']}]"
														   class="ace ace-checkbox-2 children" 
													type="checkbox" value="{$vv['id']}"/>
													<span class="lbl"> {$vv['title']}</span>
												</label>
													{notempty name='vv.children'}
													{volist name="vv.children" id="vvv"}
													<label class="layui-col-md2">
														<input lay-ignore name="rules[{$vvv['id']}]" class="ace ace-checkbox-2 children" type="checkbox" value="{$vvv['id']}" /><span> {$vvv['title']}</span>
													</label>
													{/volist}
												   	{/notempty}
											{/volist}
										</div>
									</div>
								{/notempty}
							</div>
						</div>
					</blockquote>
					{/volist}	 
				</div>
				{/empty}
				<div class="layui-form-item">
				  <div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="formDemo">提交</button>
				  </div>
				</div>
			  </form>
			</div>
		</div>
		<!-- 内容主体区域 END-->
	</div>
{include file='Public/footer' /}

<script>
    $(".children").click(function () {
        $(this).parent().parent().parent().parent().find(".father").prop("checked", true);
    })
    $(".father").click(function () {
        if (this.checked) {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", true);
        } else {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", false);
        }
    })
</script>
<script>
layui.use(['form','layer'], function(){
	var form = layui.form,jq = layui.jquery,layer=layui.layer;
	form.on('submit(formDemo)', function(data){
		loading = layer.load(2, {
			shade: [0.2,'#000']
		});
		var param = data.field;
		jq.post("{:url('update')}",param,function(data){
			//console.log(data);
			if(data.code == 1){
				layer.close(loading);
				layer.msg(data.msg, {icon: 1, time: 1000}, function(){
					//location.reload();
					location.href="{:url('index')}";
				});
			}else{
				layer.close(loading);
				layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
			}
		});
	return false;
	});
});
</script>	
